package com.meituan.stock.api.http.controller;

import com.meituan.stock.api.http.model.converter.StockBOConverter;
import com.meituan.stock.api.http.model.converter.StockVOConverter;
import com.meituan.stock.api.http.model.request.InStockHttpRequest;
import com.meituan.stock.api.http.model.request.InitStockHttpRequest;
import com.meituan.stock.api.http.model.request.OutStockHttpRequest;
import com.meituan.stock.api.http.model.response.InitStockHttpResponse;
import com.meituan.stock.biz.model.bo.StockBO;
import com.meituan.stock.biz.service.StockService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author ShenWenhao
 * @Created by ShenWenhao
 * @Date 2022/5/9 14:25
 */
@Api(tags = {"简易库存系统"})
@RestController
@RequestMapping("/stock")
public class StockController {

    @Resource
    private StockService stockService;

    @ApiOperation("初始化库存")
    @RequestMapping(value = "/init", method = RequestMethod.POST)
    public InitStockHttpResponse initStock(InitStockHttpRequest initStockHttpRequest){
        StockBO stockBO = StockBOConverter.fromInitStockHttpRequest(initStockHttpRequest);
        stockBO = stockService.initStock(stockBO);
        return StockVOConverter.fromBO(stockBO);
    }

    @ApiOperation("入库操作")
    @RequestMapping(value="/in", method = RequestMethod.POST)
    public String inStock(InStockHttpRequest inStockHttpRequest){
        return stockService.inStock(StockBOConverter.fromInStockHttpRequest(inStockHttpRequest));
    }

    @ApiOperation("出库操作")
    @RequestMapping(value="/out", method = RequestMethod.POST)
    public String outStock(OutStockHttpRequest outStockHttpRequest){
        return stockService.outStock(StockBOConverter.fromOutStockHttpRequest(outStockHttpRequest));
    }
}
